var app = angular.module("app",[]);
app.config(function($httpProvider){
    $httpProvider.defaults.transformRequest=function(obj){
        var str=[];
        for(var p in obj){
            str.push(encodeURIComponent(p)+"="+encodeURIComponent(obj[p]));
        }
        return str.join("&");
    };
    $httpProvider.defaults.headers.post={
        'Content-Type':'application/x-www-form-urlencoded'
    }
})

app.controller("PersonalController",function($scope,$http){
	$scope.initView= function(uid){
		$http({
			method:'post',
			url:webRoot+'?s=/App/Username/getUserInfo',
			data:{
				uid:uid,
			}
		}).then(function successCallback(response){
			//console.log(JSON.stringify(response));         
			$scope.info = response.data.data//最新内容数据 
			
		},function errorfunction(e){
			console.log(JSON.stringify(e));
		})	
 	}
});
document.addEventListener('plusready',function(){
	
	appElement=document.querySelector('[ng-controller=PersonalController]');
	$scope= angular.element(appElement).scope();
	var uid = plus.storage.getItem('id');
    $scope.initView(uid);
	$scope.$apply();
	
	 mui.init({
			keyEventBind: {
				backbutton: false,
				menubutton: false
			}
		});
		//获得侧滑主窗口webview对象
		var main = null;
		mui.plusReady(function () {
			main = plus.webview.currentWebview().opener();
		})
		function closeMenu () {
			mui.fire(main,"menu:swipeleft");
		}
		//优化显示出来的侧滑菜单，只需监听该菜单的左滑事件，然后将其关闭即可；在菜单上右滑，不做任何操作；
		window.addEventListener("swipeleft",closeMenu);  
		document.getElementById("close-btn").addEventListener('tap',closeMenu);
		mui.menu = closeMenu;
		
		
		var info = document.getElementById("info");
		document.getElementById("confirmBtn").addEventListener('tap', function() {
			var btnArray = ['取消', '确定'];
			mui.confirm('您确定拨打400客服电话？', ' ', btnArray, function(e) {
				if (e.index == 1) {
					tool.openNewPage('self_help_order.html');
				} else {
					return;
				}
			})
		});
		
		//多条判断跳转页面
		//个人信息
		$('.user_info').on('tap',function(){			
			tool.openNewPage('personal_info.html');
		})
		$('#perstion li').on('tap', function() {
			switch($(this).index()) {
				case 0:
					plus.webview.create('order.html').show('pop-in');
					break;
				case 1:
					plus.webview.create('wallet.html').show('pop-in');
					break;
				case 2:
					plus.webview.create('complaint.html').show('pop-in');
					break;
				case 4:
					plus.webview.create('authentication.html').show('pop-in');
					break;
				case 5:
					plus.webview.create('setting.html').show('pop-in');
					break;
			}
		})
})